package br.com.mobimenu.model.impl;

import java.util.Calendar;

import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import br.com.mobimenu.model.Entidade;


@MappedSuperclass
public abstract class EntidadeGeneric implements Entidade {

	private static final long serialVersionUID = 1343509745742953848L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;

	@Temporal(TemporalType.TIMESTAMP)
	private Calendar dataInclusao;

	@Temporal(TemporalType.TIMESTAMP)
	private Calendar dataAlteracao;

	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "usuario_inclusao_id", nullable = false)
	private Usuario usuarioInclusao;

	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "usuario_alteracao_id", nullable = false)
	private Usuario usuarioAlteracao;

	public EntidadeGeneric() {

	}

	@Override
	public boolean equals(Object obj) {
		boolean equals = false;
		if ((this.getId() == ((EntidadeGeneric) obj).getId())) {
			equals = true;
		} else if (obj == this) {
			equals = true;
		}
		return equals;
	}

	@Override
	public Calendar getDataAlteracao() {
		return this.dataAlteracao;
	}

	@Override
	public Calendar getDataInclusao() {
		return this.dataInclusao;
	}

	@Override
	public Long getId() {
		return this.id;
	}

	@Override
	public Usuario getUsuarioAlteracao() {
		return this.usuarioAlteracao;
	}

	@Override
	public Usuario getUsuarioInclusao() {
		return this.usuarioInclusao;
	}

	public void setDataAlteracao(Calendar dataAlteracao) {
		this.dataAlteracao = dataAlteracao;
	}

	public void setDataInclusao(Calendar dataInclusao) {
		this.dataInclusao = dataInclusao;
	}

	@Override
	public void setId(Long id) {
		this.id = id;
	}

	@Override
	public void setUsuarioAlteracao(Usuario usuarioAlteracao) {
		this.usuarioAlteracao = usuarioAlteracao;
	}

	@Override
	public void setUsuarioInclusao(Usuario usuarioInclusao) {
		this.usuarioInclusao = usuarioInclusao;
	}

}
